package com.study.task;

import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;


/**
 * @author
 */
//持久化
@PersistJobDataAfterExecution
//禁止并发执行(Quartz不要并发地执行同一个job定义（这里指一个job类的多个实例）)
@DisallowConcurrentExecution
@Slf4j
public class TestTask2 extends QuartzJobBean implements Job {

    @Override
    public void executeInternal(JobExecutionContext context) {
        String taskName = context.getJobDetail().getJobDataMap().getString("name");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("开始执行任务2... ...{},{}", taskName, sdf.format(new Date()));
        LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10));
    }
}
